package com.ycsj.goldmedalnewconcept.common.adapter;

import android.content.Context;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ycsj.common.base.CommonAdapter;
import com.ycsj.common.base.ViewHolder;
import com.ycsj.common.utils.ScreenUtils;
import com.ycsj.common.utils.UiUtils;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.bean.UnitGvInfo;

import java.util.List;

/**
 * 展示单元栏的适配器
 * Created by Administrator on 2019/2/20 0020.
 */

public class UnitGvAdapter extends CommonAdapter<UnitGvInfo> {
    private RelativeLayout.LayoutParams lp;

    public UnitGvAdapter(Context context, List<UnitGvInfo> datas, int layoutId) {
        super(context, datas, layoutId);
        //动态计算条目的宽高,动态修改代码
        int width = (ScreenUtils.getScreenWidth(context) - UiUtils.dp2px(8 * 5)) / 4;
        int height = width * 28 / 70;
        lp = new RelativeLayout.LayoutParams(width, height);
        lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    }


    @Override
    public void convert(ViewHolder holder, UnitGvInfo unitGvInfo) {
        TextView tv = holder.getView(R.id.tv);
        tv.setLayoutParams(lp);

        if (unitGvInfo.isSelected) {
            tv.setBackgroundResource(unitGvInfo.selectRes);
        } else {
            tv.setBackgroundResource(unitGvInfo.unSelectRes);
        }

    }
}
